<template>
	<div class="ny">
		<div class="item" @click="goTo('walllist',4,0)">
			<div class="item-text1">{{total}}</div>
			<div class="item-text2">壁纸总数</div>
		</div>
		<div class="item" @click="goTo('walllist',4,0)">
			<div class="item-text1">{{downAll}}</div>
			<div class="item-text2">壁纸总下载量</div>
		</div>
		<div class="item" @click="goTo('userList',0,1)">
			<div class="item-text1">{{users}}</div>
			<div class="item-text2">用户数量</div>
		</div>
		<div class="item" @click="goTo('userList',0,1)">
			<div class="item-text1">{{todayDown}}</div>
			<div class="item-text2">今日下载量</div>
		</div>

		<div class="item" @click="goTo('userList',0,1)">
			<div class="item-text1">{{videoUsers}}</div>
			<div class="item-text2">今日广告人数</div>
		</div>
		<div class="item" @click="goTo('userList',0,1)">
			<div class="item-text1">{{videoTimes}}</div>
			<div class="item-text2">广告次数</div>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				
				total: 0,
				downAll: 0,
				todayDown: 0,
				users: 0,
				newUsers: 0,
				videoUsers: 0,
				videoTimes: 0
			}
		},
		created() {
			let that = this
			let col = uniCloud.importObject('ny102Picture', {
				customUI: true
			})
			let col1 = uniCloud.importObject('ny106UserObj', {
				customUI: true
			})
			col.getData().then(res => {
				this.total = res.total
				this.downAll = res.data.reduce((sum, item) => sum + item.down, 0)
			})
			col1.getData().then(res => {
				let num = 0
				res.data.map((n, m) => {

					if (n.downTimes != undefined) {
						num += n.downTimes
					}
				})
				this.todayDown = num
				this.users = res.data.length
				// 获取当前日期
				let today = new Date();

				// 获取昨天日期
				let yesterday = new Date().getDate() - 86400000;
				let i = 0
				let a = 0
				res.data.map((item) => {
					a = a - 0 + (item.videoTimes - 0)
					if (item.create_date > yesterday) {
						i += 1
					}
				})
				let c = 0
				res.data.map((item) => {
					if (item.videoTimes > 0) {
						c += 1
					}

				})
				this.videoUsers = c
				this.newUsers = i
				this.videoTimes = a
			})
		},
		methods: {
			goTo(item, i, j) {
				this.$emit('go', item, i, j);
			},
			getTime(item) {
				var date = new Date(item)
				var year = date.getFullYear()
				var month = date.getMonth() + 1
				var day = date.getDate()
				var hour = date.getHours()
				var fen = date.getMinutes()
				if (month <= 9) {
					month = `0${month}`
				}
				if (day <= 9) {
					day = `0${day}`
				}
				if (hour <= 9) {
					hour = `0${hour}`
				}
				if (fen <= 9) {
					fen = `0${fen}`
				}
				return `${year}${month}${day}${hour}${fen}`
			}
		}
	}
</script>

<style lang="scss">
	.ny {
		width: 100%;
		height: 100%;
		position: relative;

		.item {
			margin: 20px;
			float: left;
			width: 230px;
			height: 140px;
			background-color: #fff;
			border-radius: 15px;

			// display: flex;
			// justify-content: center;
			// align-items: center;
			// flex-wrap: wrap;
			.item-text1 {
				margin-top: 20px;
				text-align: center;
				font-size: 50px;
				font-weight: 800;
				color: #000;
			}

			.item-text2 {
				text-align: center;
				font-size: 16px;
			}
		}
	}
</style>